package com.xyh.student.controller;

import javax.websocket.server.PathParam;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.xyh.student.entity.ExcelToDataBase;
import com.xyh.student.entity.Option;
import com.xyh.student.entity.Question;
import com.xyh.student.entity.ResponseData;
import com.xyh.student.service.QuestionService;

@RestController
@RequestMapping("/question")
public class QuestionController {

    @Autowired
    private QuestionService questionService;

    //查询所有题目
    @GetMapping("/all")
    public ResponseData findall(){
        return questionService.findAllQuestion();
    }

    //新建题目，
    /**
     * 
     * @param question
     * @param option
     * @return
     * 需要传入题目和选项
     * Question {
    String details;
    Integer type;
    Integer difficulty;
    String answer;
    Integer source;
    Integer lid;
    Integer score;}

    Option{
    String ad;
    String bd;
    String cd;
    String dd;
    String ed;
    String fd;
    String gd;
    }
     */
    @PostMapping("/insert")
    //新建题目，如果是选择题传入option
    public ResponseData insertQuestionAndOption(@PathParam("question") Question question,@PathParam("option") Option option){
        System.out.println(question+","+option);
        return questionService.insertQuestionAndOption(question, option);
    }

    //自动导入题目，需要选择题库的id，然后选择excel表格的路径
    @PostMapping("/autoInsert")
    public ResponseData autoInsertQuestion(ExcelToDataBase excelToDataBase,int liblid){
        System.out.println(excelToDataBase);
        return questionService.toDataBase(excelToDataBase,liblid);
    }

    //删除题目，传入题目id
    @PostMapping("delete/{qid}")
    public ResponseData deleteById(@PathVariable("qid") int qid){
        return questionService.deleteById(qid);
    }

    @GetMapping("/findById/{qid}")
    public ResponseData findQuestionById(@PathVariable("qid") int qid){
        return questionService.findQuestionById(qid);
    }

}
